import Vue from 'vue'


Vue.directive("enter-helper", {
  inserted(el, binding, vnode, oldVnode) {
    const {value} = binding

    const toDo = () => {
      if (Array.isArray(value)) {
        const fun = value[0]
        fun.apply(vnode, value.slice(1))

      } else if (typeof value === "function") {
        value.call(vnode)
      }
    }

    const inputList = document.getElementsByTagName('input')
    for (let inputListElement of inputList) {

      inputListElement.addEventListener('keyup', e => {
        const {key} = e
        if (key === 'Enter') toDo()
      })
    }
  }
})
